package com.vincent.template.commons.validation.validators;

import com.vincent.template.commons.validation.constraints.MatchYM;
import com.vincent.template.utils.DateUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @Author Vincent Wang
 * @Date 2020/9/8 20:58
 */
public class MatchYmValidator implements ConstraintValidator<MatchYM, String> {

    private boolean required;

    @Override
    public void initialize(MatchYM constraintAnnotation) {
        required = constraintAnnotation.required();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        return DateUtil.matchYM(required, value);
    }
}
